import java.util.Arrays;
import java.util.Collections;

/**
 * @Author: Liu, Yunfeng
 * @DateTime: 2021/7/15 20:59
 * @Description: TODO
 */
public class maximumElementAfterDecrementingAndRearranging {
    public static int maximumElementAfterDecrementingAndRearranging(int[] arr) {
        if (arr == null || arr.length < 1) {
            return 0;
        }
        Arrays.sort(arr);
        if (arr.length == 1) {
            return 1;
        }
        int result = 0;
        for(int i=0;i<arr.length; i++){
            if(arr[i]>=result+1){
                result++;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int[] arr = {1,1,1};
        System.out.println(maximumElementAfterDecrementingAndRearranging(arr));
    }
}
